<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/1/3-16:45
    // +----------------------------------------------------------------------
    // | Description:  
    // +----------------------------------------------------------------------


    namespace app\common\widget;


    use Jrk\Random;
    use think\Controller;

    class Forms extends Controller
    {


        protected function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub
            // 取消模板布局
           // $this->view->engine->layout(false);
        }


        /**
         * @param $data
         * @param $parame
         * @param $check_id
         * @return bool|mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Radio
         * @describe:radio
         */
        public function Radio($data,$parame,$check_id){
            if(!is_array($data)){
                return false;
            }
            $parm=@explode("|",$parame);
            $this->assign([
                'radio'=>$data,
                'check_ID'=>$check_id,
                'name'=>$parm[0],
                'label'=>$parm[1],
                'word'=>isset($parm[2])?$parm[2]:"",
            ]);

            return $this->fetch("common@widget/radio");
        }

        /**
         * @param $name
         * @param $laber
         * @param $pla
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Search
         * @describe:搜索框
         */
        public function Search($name,$laber,$pla){
            $this->assign([
                'name'=>$name,
                'laber'=>$laber,
                'pla'=>$pla
            ]);

            return $this->fetch("common@widget/search");
        }


        /**
         * @param $filter
         * @param $id
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: table
         * @describe:表格
         */
        public function table($filter="tableFilter",$id="tableFilter"){
            $this->assign([
                'tableFilter'=>empty($filter)?"tableFilter":$filter,
                'id'=>empty($id)?"tableFilter":$id,
            ]);
            return $this->fetch("common@widget/table");

        }

        /**
         * @param $title
         * @param int $t
         * @param string $type
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Addbtn
         * @describe:添加按钮
         */
        public function Addbtn($title="添加",$t=1,$type="add"){
            $this->assign([
                'title'=>$title,
                't'=>$t,
                'type'=>$type
            ]);
            return $this->fetch("common@widget/addbtn");
        }


        /**
         * @param string $type
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: reload
         * @describe:刷新
         */
        public function reload($type='reload'){
            $this->assign([
                'type'=>$type
            ]);
            return $this->fetch("common@widget/reload");
        }


        /**
         * @param string $title
         * @param int $t
         * @param string $type
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Delbtn
         * @describe:删除
         */
        public function Delbtn($title="删除",$t=1,$type="del"){
            $this->assign([
                'title'=>$title,
                't'=>$t,
                'type'=>$type
            ]);
            return $this->fetch("common@widget/delbtn");
        }



        /**
         * @param string $title
         * @param string $type
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Editbtn
         * @describe:编辑按钮
         */
        public function Editbtn($title="编辑",$type="edit"){
            $this->assign([
                'title'=>$title,
                'type'=>$type
            ]);
            return $this->fetch("common@widget/editbtn");
        }


        /**
         * @param $idStr
         * @param $textStr
         * @param $selectId
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: switchCheck
         * @describe:SWITCH组件开关
         */
        function switchCheck($idStr, $textStr, $selectId)
        {
            //渲染界面
            $this->assign('idStr',$idStr);
            $this->assign('textStr',$textStr);
            $this->assign("selectId",$selectId);
            return $this->fetch("common@widget/switch_checked");
        }

        /**
         * @param $param
         * @param $list
         * @param $selectId
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: singleSelect
         * @describe:下拉单选
         */
        function singleSelect($param, $list, $selectId)
        {
            $arr = explode('|', $param);

            //参数
            $idStr = $arr[0];
            $isV = $arr[1];
            $msg = $arr[2];
            $show_name = $arr[3];
            $show_value = $arr[4];

            $this->assign('idStr',$idStr);
            $this->assign('isV',$isV);
            $this->assign('msg',$msg);
            $this->assign('show_name',$show_name);
            $this->assign('show_value',$show_value);
            $this->assign('dataList',$list);
            $this->assign("selectId",$selectId);
            return $this->fetch("common@widget/single_select");
        }


        /**
         * @param $filter
         * @param $btnname
         * @param $cz
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: submit
         * @describe:提交按钮
         */
        public function submit($filter,$btnname,$cz=1){

            $this->assign('filter',$filter);
            $this->assign('cz',$cz);
            $this->assign("btnname",$btnname);
            return $this->fetch("common@widget/submit");
        }




        /**
         * @param $param
         * @param string $value
         * @param int $width
         * @param int $height
         * @return mixed
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/1 0001
         * @name: Pic
         * @describe：上传图片及选择素材
         */
        public function Pic($param,$value='',$width=250,$height=400){
            $arr = explode('|', $param);
            //参数
            $name = $arr[0]; //name值
            $label = empty($arr[1])?'上传图片':$arr[1];
            $placeholder = empty($arr[2])? '请上传图片': $arr[2];
            $verify = empty($arr[3])? '': $arr[3];
            $btn= empty($arr[4])? '上传图片': $arr[4];
            $path=Random::nozero(6);
            $upload=Random::nozero(4);
            $choose=Random::nozero(3);
            $show=Random::nozero(5);

            $this->assign('name',$name);
            $this->assign('value',$value);
            $this->assign('label',$label);
            $this->assign('placeholder',$placeholder);
            $this->assign('verify',$verify);
            $this->assign('btn',$btn);
            $this->assign('width',$width);
            $this->assign('heig',$height);
            $this->assign('path',$path);
            $this->assign('upload',$upload);
            $this->assign('choose',$choose);
            $this->assign('show',$show);
            return $this->fetch('common@widget/pic');
        }


        /**
         * @param $param
         * @param string $value
         * @return mixed
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/1 0001
         * @name: Files
         * @describe：文件选择
         */
        public function Files($param,$value=''){
            $arr = explode('|', $param);
            //参数
            $name = $arr[0]; //name值
            $label = empty($arr[1])?'上传附件':$arr[1];
            $placeholder = empty($arr[2])? '请上传附件': $arr[2];
            $verify = empty($arr[3])? '': $arr[3];
            $btn= empty($arr[4])? '上传附件': $arr[4];
            $path=Random::nozero(6);
            $upload=Random::nozero(4);
            $choose=Random::nozero(3);
            $this->assign('name',$name);
            $this->assign('value',$value);
            $this->assign('label',$label);
            $this->assign('placeholder',$placeholder);
            $this->assign('verify',$verify);
            $this->assign('btn',$btn);
            $this->assign('path',$path);
            $this->assign('upload',$upload);
            $this->assign('choose',$choose);
            return $this->fetch('common@widget/file');
        }


        /**
         * @param $name
         * @param $imgUrl
         * @param string $size
         * @param string $nameStr
         * @param string $sizeStr
         * @param string $cropSize
         * @param string $cropRate
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: uploadImg
         * @describe:上传图片裁剪
         */
        function uploadImg($name, $imgUrl, $size='100x100', $nameStr='', $sizeStr='', $cropSize='300x300', $cropRate='')
        {
            $size 	= $size ? $size : '100x100'; //默认尺寸 100x100
            $nameStr = $nameStr ? $nameStr : "图片";
            $isCrop = $cropSize ? 1 : 2;
            $cropSize = $cropSize ? $cropSize : '300x300'; //默认裁剪尺寸 300x300
            $cropRate = $cropRate ? $cropRate : 1/1;

            //长宽
            $itemArr = explode('x', $size);
            //裁剪尺寸
            $cropArr = explode('x', $cropSize);

            $this->assign('name', $name);
            $this->assign('imgUrl', $imgUrl);
            $this->assign('img', $imgUrl);
            $this->assign('imgW', $itemArr[0]);
            $this->assign('imgH', $itemArr[1]);
            $this->assign('nameStr',$nameStr);
            $this->assign('sizeStr',$sizeStr);
            $this->assign('cropW',$cropArr[0]);
            $this->assign('cropH',$cropArr[1]);
            $this->assign('cropRate',$cropRate);
            $this->assign('isCrop',$isCrop);
            return $this->fetch("common@widget/upload_singleImg");
        }



        /**
         * @param $name
         * @param $imageList
         * @param $imgMsg
         * @param $size
         * @param int $maxNum
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: uploadMultImg
         * @describe:多图上传
         */
        function uploadMultImg($name, $imageList, $imgMsg='', $size='100x100', $maxNum=30)
        {
            //字段名称
            $name = isset($name) ? trim($name) : 'file';
            //长宽
            $size 	= isset($size) ? trim($size) : '100x100'; //图片尺寸  100 x 100
            $sizeArr = explode('x', $size);
            //最大上传张数
            $maxNum = $maxNum ? $maxNum : 5;//默认上传5张

            $this->assign('name', $name);
            $this->assign('maxNum',$maxNum);
            $this->assign('imgMsg',$imgMsg);
            $this->assign('imgW', $sizeArr[0]);
            $this->assign('imgH', $sizeArr[1]);
            $this->assign('imageList',$imageList);
            return $this->fetch("common@widget/upload_multipleImg");
        }



        /**
         * @param $param
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Ueditor
         * @describe:百度编辑器
         */
        public function Ueditor($param,$value='',$min=0){
            $arr = explode('|', $param);
            //参数
            $name = $arr[0];
            $laber = $arr[1];
            $placeholder = empty($arr[2])? $laber: $arr[2];
            $ud_height = empty($arr[3])? '420': $arr[3];
            $this->assign('name', $name);
            $this->assign('laber',$laber);
            $this->assign('placeholder',$placeholder);
            $this->assign('ud_height', $ud_height);
            $this->assign('value', $value);
            $this->assign('min', $min);
            return $this->fetch("common@widget/ueditor");
        }



        /**
         * @param $param
         * @param $value
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Layedit
         * @describe:layui edit
         */
        public function Layedit($param,$value,$hg=200){
            $arr = explode('|', $param);

            $name=empty($arr[0])?'content':$arr[0];
            $laber=empty($arr[1])?'内容':$arr[1];
            $placeholder = empty($arr[2])? $laber: $arr[2];
            $id= empty($arr[3])? rand(1,8): $arr[3];
            $verify=isset($arr[4])?$arr[4] :'';
            $lay_height=$hg;

            $this->assign('name', $name);
            $this->assign('laber',$laber);
            $this->assign('placeholder',$placeholder);
            $this->assign('id', $id);
            $this->assign('verify', $verify);
            $this->assign('lay_height', $lay_height);
            $this->assign('value',$value);
            return $this->fetch("common@widget/layedit");
        }



        /**
         * @param $name
         * @param $imageurl
         * @param $verify
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: Webuploader
         * @describe:webupload 图片上传
         */
        public function Webuploader($name,$imageurl,$verify){
            $this->assign('name', empty($name) ? 'imgs':$name); //图片存储的表单name值
            $this->assign('imageurl',empty($imageurl)? 'images':$imageurl);
            $this->assign('verify',$verify);
            return $this->fetch("common@widget/webuploader");
        }

    }